<?php
/**
 * Created by PhpStorm.
 * User: tjjs
 * Date: 17-6-19
 * Time: 下午1:44
 */

namespace ActionsHttp;

use Data\Tree_gg_DAO;
use Data\Tree_group_DAO;
use Data\Tree_species_DAO;

class GroupList extends BaseActionHttp
{
    public function doAction() {
        parent::doAction();
        $customer_id_random_str = $this->data[CUSTOMER_ID];
        $customer_id = substr($customer_id_random_str,10);
        // 检测登陆是否过期
        if (!($this->checkSession($customer_id))) {
            return;
        }

        $species_id = $this->data[SPECIES_ID];
        if (!$species_id) {
            return $this->SendErrMsg("参数错误，品种id为空");
        }
        $species_record = Tree_species_DAO::getRecord($species_id);
        $gg_id = $species_record->getGG_ID();
        $gg_record = Tree_gg_DAO::getRecord($gg_id);
        $gg_dw = $gg_record->getGG_DW();

        $group_list = Tree_group_DAO::getTxListBySpecies_id($species_id);

        $results = array();
        foreach($group_list as $group_record){
            $gg_string = $group_record[GG_ARRAY];
            if ($gg_string) {
                $group_array = explode(',',$gg_string);
                $group_arr = array();
                $group_record[GG_ARRAY] = array();

                foreach ($group_array as $group) {
                    $group_arr[GG_CS] = $group;
                    $group_arr['gg_cs_name'] = $group.$gg_dw;
                    $group_record[GG_ARRAY][] = $group_arr;
                }
            } else {
                $group_record[GG_ARRAY] = array();
            }
            $results[] = $group_record;
        }

        // 返回数据
        $this->setValue(GROUP_LIST,$results);
        $this->ResponseDataToCurrentClient();

    }
}